﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WS.EKA.FJYCM.Business;
using WS.EKA.FJYCM.Utilities;

namespace WS.EKA.FJYCM.WebUI.UserControls
{
    public partial class SystenEventsHolder : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitialSystemEvents();
        }
        
        private void InitialSystemEvents()
        {
            var sysEvents_core = SystemAccess.GetSystemsByLevel(SecurityLevel.Core).OrderByDescending(x => x.TotalCount).ToList();
            var sysEvents_Imp = SystemAccess.GetSystemsByLevel(SecurityLevel.Important).OrderByDescending(x => x.TotalCount).ToList();
            var sysEvents_Nor = SystemAccess.GetSystemsByLevel(SecurityLevel.Normal).OrderByDescending(x => x.TotalCount).ToList();

            int pageCount = 0;

            for (int i = 1; i <= (sysEvents_core.Count / 12) + 1; i++)
            {
                pageCount++;
                SystemEventsOverView uc_core_1 = (SystemEventsOverView)Page.LoadControl("usercontrols/SystemEventsOverView.ascx");
                uc_core_1.ID = "sysEvent_core" + i;
                uc_core_1.SystemType = "核心业务系统";
                uc_core_1.Order = pageCount;
                uc_core_1.DataSource = sysEvents_core.Skip(12 * (i - 1)).Take(12).ToList();
                phSystemEvents.Controls.Add(uc_core_1);

            }
            for (int i = 1; i <= (sysEvents_Imp.Count / 12) + 1; i++)
            {
                pageCount++;
                SystemEventsOverView uc_core_1 = (SystemEventsOverView)Page.LoadControl("usercontrols/SystemEventsOverView.ascx");
                uc_core_1.ID = "sysEvent_imp" + i;
                uc_core_1.SystemType = "重要业务系统";
                uc_core_1.Order = pageCount;
                uc_core_1.DataSource = sysEvents_Imp.Skip(12 * (i - 1)).Take(12).ToList();
                phSystemEvents.Controls.Add(uc_core_1);

            }
            for (int i = 1; i <= (sysEvents_Nor.Count / 12) + 1; i++)
            {
                pageCount++;
                SystemEventsOverView uc_core_1 = (SystemEventsOverView)Page.LoadControl("usercontrols/SystemEventsOverView.ascx");
                uc_core_1.ID = "sysEvent_nor" + i;
                uc_core_1.SystemType = "普通业务系统";
                uc_core_1.Order = pageCount;
                uc_core_1.DataSource = sysEvents_Nor.Skip(12 * (i - 1)).Take(12).ToList();
                phSystemEvents.Controls.Add(uc_core_1);
            }
            this.hfSysEventsPageCount.Value = pageCount.ToString();
        }
    }
}